<?php
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bienvenue à vous connecter forme!</title>
<link href="css/login_style.css" rel="stylesheet" type="text/css" />
</head>
<?php
	require_once("../includes/initialize.php");
	include("global.php");
	
	if(isset($_POST["btnsubmit"]))
	{
		openConnection();
		$user = trim($_POST["txtuser_name"]);
		$pwd = trim($_POST["txtpassword"]);
		if($user != "" and $pwd != "")
		{
			$found = findUser($user, $pwd);
			if($found)
			{
				//login($found);
				$expire=time()+60*60*24*2;
				setcookie("user", "login", $expire);	
				pageRedirect("index.php","");			
			}
			else
			{
				errorMessage("Nom d'utilisateur et Mot de passe incorrect");					
			}
		}
		elseif($user == "Nom utilisateur" and $pwd == "Password")
		{
			errorMessage("Nom d'utilisateur et mot de passe n'est nécessaire!");
		}
		closeConnection();
	}
	
?>
<body>
<div id="wraper">
	<div id="field_set">
    <script language="javascript" type="text/javascript">
		function clearText(field)
			{
				if (field.defaultValue == field.value) field.value = '';
				else if (field.value == '') field.value = field.defaultValue;
			}
	</script>
    <form form="frmlogin" action="login.php" method="post">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <?php
			  		if(@$errors!="")
					{
						echo "<tr>";
                			echo "<td>".$errors."</td>";
              			echo "</tr>";
					}
              ?>
              
              <tr>
                <td> <input class="user"  type="text" name="txtuser_name" value="Nom utilisateur" size="30" onfocus="clearText(this)" onblur="clearText(this)" />
               
                </td>
              </tr>
              <tr>
                <td><input class="pwd" type="password" name="txtpassword" value="Password" size="30" onfocus="clearText(this)" onblur="clearText(this)" /></td>
              </tr>
              <tr>
                <td><input class="btn" type="submit"  name="btnsubmit"  value=""  /></td>
              </tr>
       </table>
  </form>
	</div>
</body>
</html>